#!/opt/internet/bin/perl -- -*-perl-*-

# ------------------------------------------------------------

# Form-mail.pl, by Reuven M. Lerner (reuven@the-tech.mit.edu).
# This is a rewrite of a program that was trashed by our power
# surge in the middle of February 1994.

# ------------------------------------------------------------

# Bugs and other fixes

# March 1, 1994 (Reuven)
# Fixed security hole that could result from people
# executing subshells
# January 5, 1995 (McGredy)
# Modified for Pure Software, Inc.
# ------------------------------------------------------------

# Define fairly-constants
$mailprog = '/usr/ucb/mail -s "PS Web Eval Form"';
# Ric: Change this to "support@pure.com" when it goes to Test
# Ric: Change this to "ricm@rahul.net" when installed on rahul or mnl

$recipient = 'ricm@rahul.net, info-home@pure.com';

# Print out what we need
print "Content-type: text/html\n\n";
print "<img src=/pure/logo.gif>";
print "<p><hr><p>";
print "<Head><Title>Thank You</Title></Head>";
print "<Body><H1>Thank you for your request.</H1>";

# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);

foreach $pair (@pairs)
{
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

    # Stop people from using subshells to execute commands
    $value =~ s/~!/ ~!/g;

    # Uncomment for debugging purposes
    # print "Setting $name to $value<P>";

    $FORM{$name} = $value;
}

# Now send mail to $recipient

open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
print MAIL "Pure Software Web Page Evaluation Sftware Request:\n";
print MAIL "--------------------------------------------------\n\n";
print MAIL "Name:      $FORM{'From'}\n";
print MAIL "Title:     $FORM{'Title'}\n";
print MAIL "Company:   $FORM{'Compny'}\n";
print MAIL "Street:    $FORM{'Street'}\n";
print MAIL "Street2:   $FORM{'Street2'}\n";
print MAIL "City:      $FORM{'City'}\n";
print MAIL "State:     $FORM{'State'}\n"; 
print MAIL "Zip:       $FORM{'Zip'}\n";
print MAIL "Country:   $FORM{'Country'}\n";
print MAIL "EMail:     $FORM{'Reply-To'}\n";
print MAIL "Phone:     $FORM{'Phone'}\n";
print MAIL "Fax:       $FORM{'Fax'}\n";
print MAIL "Does your organization sell software? $FORM{'ISV'}\n";
print MAIL "Is your organization involved with in-house software development? $FORM{'MIS'}\n";
print MAIL "Are you part of a systems integration team? $FORM{'sysint'}\n";
print MAIL "Other Organization Type: $FORM{'otherorg'}\n";
print MAIL "Development Environment:\n";
print MAIL "    C: $FORM{'C'} C++: $FORM{'C++'} X: $FORM{'X'} Windows: $FORM{'Win'}\n";
print MAIL "    Other Development Environment(s): $FORM{'otherdev'}\n";
print MAIL "Hardware Environment:\n";
print MAIL "    Sun: $FORM{'Sun'} HP: $FORM{'HP'} SGI: $FORM{'SGI'}\n";
print MAIL "    Other: $FORM{'otherhdwe'}\n";
print MAIL "Type of application(s) you are working on:\n";
print MAIL "    $FORM{'appsworking'}\n";
print MAIL "Number of Developers on team:    $FORM{'numdevteam'}\n";
print MAIL "Number of Developers in company: $FORM{'numdevcmpy'}\n";
print MAIL "Please send me the following FREE evaluation software:\n";
print MAIL "    Purify: $FORM{'SendPYeval'} Quantify: $FORM{'SendQYeval'} PureLink: $FORM{'sendPLeval'} PureCoverage: $FORM{'sendPCeval'}\n";
print MAIL "Please send me more information regarding:\n";
print MAIL "    Purify'd Partners Program: $FORM{'partners'} Pure Software Inc: $FORM{'sendPSinfo'}\n";
print MAIL "    Other (please Specify): $FORM{'otherinfo'}\n";
print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n";
print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
close (MAIL);


print "<P>";
print "<ul><li>Return to the <A HREF=\"/pure/index.html\">Pure Software Inc. Home 
Page
 </A>, if you want.</ul><P><hr>";
print "<p>Your request has been forwarded to Pure Software Inc.";

